#include "my_gui.h"
#include "lvgl.h"
#include "my_chart.h"
#include <stdio.h>



///**< X:24 Y:20*/
LV_IMG_DECLARE(img_bg2);
LV_IMG_DECLARE(img_pt1);
LV_IMG_DECLARE(img_st1);
LV_IMG_DECLARE(img_ab1);
LV_IMG_DECLARE(img_cap1);
LV_IMG_DECLARE(img_ct1);
LV_IMG_DECLARE(img_pa1);
LV_IMG_DECLARE(img_wb1);
LV_IMG_DECLARE(img_wf1);
LV_FONT_DECLARE(font30);

lv_obj_t *img;
lv_obj_t *one;
lv_obj_t *two;
lv_obj_t *three;
//lv_obj_t *four;
//lv_obj_t *five;
//lv_obj_t *six;
lv_obj_t *seven;
//lv_obj_t *eight;
//void lv_scr_load_anim(lv_obj_t *scr, lv_scr_load_anim_t anim_type ,uint32_t time, uint32_t delay, bool auto_del);

void my_gui(void)
{

///**< 弹性布局样式 */
//    static lv_style_t style;
//    lv_style_init(&style);
//    lv_style_set_flex_flow(&style, LV_FLEX_FLOW_ROW_WRAP);
//    lv_style_set_flex_main_place(&style, LV_FLEX_ALIGN_SPACE_EVENLY);
//    lv_style_set_layout(&style, LV_LAYOUT_FLEX);

/**< 字体样式 */
    static lv_style_t style_wd;
    lv_style_init(&style_wd);
    lv_style_set_text_font(&style_wd, &font30);
    //lv_style_set_align(&style_wd, LV_ALIGN_TOP_MID);
    lv_style_set_text_color(&style_wd, lv_color_hex(0xffffff));

/**< 矩形框样式 */
    static lv_style_t style_rg;
    lv_style_init(&style_rg);
    lv_style_set_width(&style_rg, 170);
    lv_style_set_height(&style_rg, 170);

///**< 创建菜单样式 */
//    lv_obj_t * menu = lv_menu_create(lv_scr_act());
//    lv_obj_set_size(menu, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL));
//    lv_obj_center(menu);

/**< 第二界面初始化 */
    one = lv_obj_create(NULL);
    lv_obj_set_size(one, LV_SIZE_CONTENT, LV_SIZE_CONTENT);

    two = lv_obj_create(NULL);
    lv_obj_set_size(two, LV_SIZE_CONTENT, LV_SIZE_CONTENT);

    three = lv_obj_create(NULL);
    lv_obj_set_size(three, LV_SIZE_CONTENT, LV_SIZE_CONTENT);

    seven = lv_obj_create(NULL);
    lv_obj_set_size(seven, LV_SIZE_CONTENT, LV_SIZE_CONTENT);

/**<  背景图片*/
    img = lv_img_create(lv_scr_act());
    lv_img_set_src(img, &img_bg2);
    lv_obj_set_size(img, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
    lv_obj_align(img,LV_ALIGN_CENTER, 0,0);
    //lv_obj_add_style(img, &style, 0);

/**< 图片按钮矩形框 */

    lv_obj_t * obj1 = lv_obj_create(img);
    lv_obj_align_to(obj1, img, LV_ALIGN_TOP_LEFT, 24, 80);
    lv_obj_set_style_opa(obj1,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj1, &style_rg, 0);

    lv_obj_t * obj2 = lv_obj_create(img);
    lv_obj_align_to(obj2, img, LV_ALIGN_TOP_LEFT, 24+194, 80);
    lv_obj_set_style_opa(obj2,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj2, &style_rg, 0);

     lv_obj_t * obj3 = lv_obj_create(img);
    lv_obj_align_to(obj3, img, LV_ALIGN_TOP_LEFT, 24+194*2, 80);
    lv_obj_set_style_opa(obj3,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj3, &style_rg, 0);

    lv_obj_t * obj4 = lv_obj_create(img);
    lv_obj_align_to(obj4, img, LV_ALIGN_TOP_LEFT, 24+194*3, 80);
    lv_obj_set_style_opa(obj4,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj4, &style_rg, 0);

    lv_obj_t * obj5 = lv_obj_create(img);
    lv_obj_align_to(obj5, img, LV_ALIGN_TOP_LEFT, 24, 80+170+20);
    lv_obj_set_style_opa(obj5,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj5, &style_rg, 0);

    lv_obj_t * obj6 = lv_obj_create(img);
    lv_obj_align_to(obj6, img, LV_ALIGN_TOP_LEFT, 24+194, 80+170+20);
    lv_obj_set_style_opa(obj6,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj6, &style_rg, 0);

    lv_obj_t * obj7 = lv_obj_create(img);
    lv_obj_align_to(obj7, img, LV_ALIGN_TOP_LEFT, 24+194*2, 80+170+20);
    lv_obj_set_style_opa(obj7,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj7, &style_rg, 0);

    lv_obj_t * obj8 = lv_obj_create(img);
    lv_obj_align_to(obj8, img, LV_ALIGN_TOP_LEFT, 24+194*3, 80+170+20);
    lv_obj_set_style_opa(obj8,600, LV_STATE_DEFAULT);
    lv_obj_add_style(obj8, &style_rg, 0);



/**< 图片按钮 */
    lv_obj_t *imgbtn1 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn1,LV_IMGBTN_STATE_RELEASED, NULL, &img_st1, NULL);
    lv_obj_set_size(imgbtn1, 130, 130);
    lv_obj_align_to(imgbtn1, obj1, LV_ALIGN_BOTTOM_MID, 0, 20);
    lv_obj_add_event_cb(imgbtn1, my_event_cb_one, LV_EVENT_CLICKED, one);


    lv_obj_t *imgbtn2 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn2,LV_IMGBTN_STATE_RELEASED, NULL, &img_wf1, NULL);
    lv_obj_set_size(imgbtn2, 130, 130);
    lv_obj_align_to(imgbtn2, obj2, LV_ALIGN_BOTTOM_MID, 0, 20);
    lv_obj_add_event_cb(imgbtn2, my_event_cb_two, LV_EVENT_CLICKED, two);


    lv_obj_t *imgbtn3 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn3,LV_IMGBTN_STATE_RELEASED, NULL, &img_pa1, NULL);
    lv_obj_set_size(imgbtn3, 130, 130);
    lv_obj_align_to(imgbtn3, obj3, LV_ALIGN_BOTTOM_MID, 0, 20);
    lv_obj_add_event_cb(imgbtn3, my_event_cb_three, LV_EVENT_CLICKED, three);

    lv_obj_t *imgbtn4 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn4,LV_IMGBTN_STATE_RELEASED, NULL, &img_cap1, NULL);
    lv_obj_set_size(imgbtn4, 130, 130);
    lv_obj_align_to(imgbtn4, obj4, LV_ALIGN_BOTTOM_MID, 0, 20);

    lv_obj_t *imgbtn5 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn5,LV_IMGBTN_STATE_RELEASED, NULL, &img_wb1, NULL);
    lv_obj_set_size(imgbtn5, 130, 130);
    lv_obj_align_to(imgbtn5, obj5, LV_ALIGN_BOTTOM_MID, 0, 20);

    lv_obj_t *imgbtn6 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn6,LV_IMGBTN_STATE_RELEASED, NULL, &img_pt1, NULL);
    lv_obj_set_size(imgbtn6, 130, 130);
    lv_obj_align_to(imgbtn6, obj6, LV_ALIGN_BOTTOM_MID, 0, 20);


    lv_obj_t *imgbtn7 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn7,LV_IMGBTN_STATE_RELEASED, NULL, &img_ct1, NULL);
    lv_obj_set_size(imgbtn7, 130, 130);
    lv_obj_align_to(imgbtn7, obj7, LV_ALIGN_BOTTOM_MID, 0, 20);
    lv_obj_add_event_cb(imgbtn7, my_event_cb_seven, LV_EVENT_CLICKED, seven);


    lv_obj_t *imgbtn8 = lv_imgbtn_create(img);
    lv_imgbtn_set_src(imgbtn8,LV_IMGBTN_STATE_RELEASED, NULL, &img_ab1, NULL);
    lv_obj_set_size(imgbtn8, 130, 130);
    lv_obj_align_to(imgbtn8, obj8, LV_ALIGN_BOTTOM_MID, 0, 20);


/**< 按键字 */
    lv_obj_t *label1 = lv_label_create(img);
    lv_obj_align_to(label1,imgbtn1 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label1,"自动运行");
    lv_obj_add_style(label1, &style_wd, 0);

    lv_obj_t *label2 = lv_label_create(img);
    lv_obj_align_to(label2,imgbtn2 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label2,"波形查看");
    lv_obj_add_style(label2, &style_wd, 0);

    lv_obj_t *label3 = lv_label_create(img);
    lv_obj_align_to(label3,imgbtn3 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label3,"运行参数");
    lv_obj_add_style(label3, &style_wd, 0);

    lv_obj_t *label4 = lv_label_create(img);
    lv_obj_align_to(label4,imgbtn4 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label4,"电容参数");
    lv_obj_add_style(label4, &style_wd, 0);

    lv_obj_t *label5 = lv_label_create(img);
    lv_obj_align_to(label5,imgbtn5 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label5,"网络参数");
    lv_obj_add_style(label5, &style_wd, 0);

    lv_obj_t *label6 = lv_label_create(img);
    lv_obj_align_to(label6,imgbtn6 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label6,"保护参数");
    lv_obj_add_style(label6, &style_wd, 0);

    lv_obj_t *label7 = lv_label_create(img);
    lv_obj_align_to(label7,imgbtn7 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label7,"手动控制");
    lv_obj_add_style(label7, &style_wd, 0);

    lv_obj_t *label8 = lv_label_create(img);
    lv_obj_align_to(label8,imgbtn8 , LV_ALIGN_OUT_TOP_MID, -40, -10);
    lv_label_set_text(label8,"关于我们");
    lv_obj_add_style(label8, &style_wd, 0);


/**< 第二界面 & 返回按钮*/
    lv_obj_t *back_btn1 = lv_btn_create(one);
    lv_obj_t *back_btn_label1 = lv_label_create(back_btn1);
    lv_label_set_text(back_btn_label1, "back");
    lv_obj_add_style(back_btn_label1, &style_wd, 0);
    lv_obj_add_event_cb(back_btn1, my_event_cb_back, LV_EVENT_CLICKED, img);

    lv_obj_t *back_btn2 = lv_btn_create(two);
    lv_obj_t *back_btn_label2 = lv_label_create(back_btn2);
    lv_label_set_text(back_btn_label2, "back");
    lv_obj_add_style(back_btn_label2, &style_wd, 0);
    lv_obj_add_event_cb(back_btn2, my_event_cb_back, LV_EVENT_CLICKED, img);

    lv_obj_t *back_btn3 = lv_btn_create(three);
    lv_obj_t *back_btn_label3 = lv_label_create(back_btn3);
    lv_label_set_text(back_btn_label3, "back");
    lv_obj_add_style(back_btn_label3, &style_wd, 0);
    lv_obj_add_event_cb(back_btn3, my_event_cb_back, LV_EVENT_CLICKED, img);

    lv_obj_t *back_btn7 = lv_btn_create(seven);
    lv_obj_t *back_btn_label7 = lv_label_create(back_btn7);
    lv_label_set_text(back_btn_label7, "back");
    lv_obj_add_style(back_btn_label7, &style_wd, 0);
    lv_obj_add_event_cb(back_btn7, my_event_cb_back, LV_EVENT_CLICKED, img);

/**< 标题 */
    lv_obj_t *label = lv_label_create(lv_scr_act());
    lv_obj_set_style_text_font(label, &font30, LV_STATE_DEFAULT);
    lv_label_set_text(label,"#0ad1d3 河南柏科沃电子科技有限公司#");
    lv_label_set_recolor(label,true);
    lv_obj_align_to(label, img, LV_ALIGN_TOP_MID, 0, 30);

}
/**< 事件响应 创建第二界面 */
void my_event_cb_back(lv_event_t *event)
{
    lv_obj_t * img = lv_event_get_user_data(event);
    lv_scr_load_anim(img, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
}

void my_event_cb_one(lv_event_t *event)
{
    one = lv_event_get_user_data(event);
    lv_scr_load_anim(one, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);

}

void my_event_cb_two(lv_event_t *event)
{
    two = lv_event_get_user_data(event);
    lv_scr_load_anim(two, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
    my_chart(two);

}

void my_event_cb_three(lv_event_t *event)
{
    three = lv_event_get_user_data(event);
    lv_scr_load_anim(three, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
    my_run(three);

}

void my_event_cb_seven(lv_event_t *event)
{
    seven = lv_event_get_user_data(event);
    lv_scr_load_anim(seven, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
    my_control(seven);

}
